package com.i2works.smartluolong.web.config;

import com.i2works.smartluolong.web.utils.ResubmitInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * web配置，相当于（web.xml）
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2017/12/15 10:22
 */
@Configuration
public class WebAdapterConfiguration extends WebMvcConfigurerAdapter {
    //日志
    private static final Logger logger = LoggerFactory.getLogger(WebAdapterConfiguration.class);

    /**
     * 注册拦截器
     * addPathPatterns 用于添加拦截规则
     * excludePathPatterns 用户排除拦截
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //重复提交拦截器
        registry.addInterceptor(new ResubmitInterceptor()).addPathPatterns("/user/**");
        logger.info("注册 --> 表单重复提交拦截器(ResubmitInterceptor)....");
        super.addInterceptors(registry);
    }

    /**
     * 注册静态路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/asset/**").addResourceLocations("classpath:/asset/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        logger.info("注册 --> 静态路径(asset、static)....");
        super.addResourceHandlers(registry);
    }


}
